<?php
  
     /*
      * Following code will create a new row
      * All details are read from HTTP Post Request
      */
      
     // array for JSON response
     $response = array();
      
     // check for required fields
     
	$place_name 	= $_POST['place_name'];
	$address  		= $_POST['address'];
	$district_id   	= $_POST['district_id'];
	(int)$district_id ;
	$longitude 		= $_POST['longitude']; 
	$latitude      	= $_POST['latitude'];
	$phone_number  	= $_POST['phone_number'];
	$fax_number    	= $_POST['fax_number'];
	$email         	= $_POST['email'];
	$website       	= $_POST['website'];
	$open_time     	= $_POST['open_time'];
	$close_time    	= $_POST['close_time'];
	$lowest_price  	= $_POST['lowest_price'];
	$hightest_price	= $_POST['hightest_price'];
	$description   	= $_POST['description'];
	$url_avatar     = $_POST['url_avatar'];
	$name_avatar    = $_POST['name_avatar'];
  
	 // include db connect class
	 require_once __DIR__ . '/db_connect.php';
  
	 // connecting to db
	 $db = new DB_CONNECT();
  
	$result = mysql_query("INSERT INTO `place`( `place_name`
												, `address`
												, `district_id`
												, `longitude`
												, `latitude`
												, `phone_number`
												, `fax_number`
												, `email`
												, `website`
												, `open_time`
												, `close_time`
												, `lowest_price`
												, `hightest_price`
												, `description`
												, `url_avatar`
												, `name_avatar`
												, `date_create`
												, `public`
												, `delete`) 
											VALUES('$place_name'
												,'$address'
												,'$district_id'
												,'$longitude'
												,'$latitude'
												,'$phone_number'
												,'$fax_number'
												,'$email'
												,'$website'
												,'$open_time'
												,'$close_time'
												,'$lowest_price'
												,'$hightest_price'
												,'$description'
												,'$url_avatar'
												,'$name_avatar
												,NOW()
												,1
												,0)");
	 // mysql inserting a new row
	 /*$result = mysql_query("INSERT INTO `place`(`place_name`, 
												`address`, 
												`longitude`, 
												`latitude`, 
												`district_id`, 
												`phone_number`, 
												`fax_number`, 
												`email`, 
												`website`, 
												`open_time`, 
												`close_time`, 
												`lowest_price`, 
												`hightest_price`,
												`visa_master`, 
												`car_parking`, 
												`moto_parking`, 
												`delivery`, 
												`wifi`, 
												`description`, 
												`public`, 
												`delete`, 
												`date_create`, 
												`url_image`) 
											VALUES(`$place_name`, 
												`$address`, 
												`$longitude`, 
												`$latitude`, 
												`$district_id`, 
												`$phone_number`, 
												`$fax_number`, 
												`$email`, 
												`$website`, 
												`$open_time`, 
												`$close_time`,  
												`$lowest_price`, 
												`$hightest_price`,
												`$visa_master`, 
												`$car_parking`, 
												`$moto_parking`, 
												`$delivery`, 
												`$wifi`, 
												`$description`, 
												`$public`, 
												`$delete`, 
												NOW(), 
												`$url_image`)");*/
												
	 $id = mysql_insert_id();
	 // check if row inserted or not
	 if ($result) {
		 // successfully inserted into database
		 $response["success"] = 1;
		 $response["message"] = "Insert successfully created.";
		 $response["place_id"] = $id;
  
		 // echoing JSON response
		 echo json_encode($response);
	 } else {
		 // failed to insert row
		 $response["success"] = 0;
		 $response["message"] = "Oops! An error occurred.";
  
		 // echoing JSON response
		 echo json_encode($response);
	 }
 }
 ?>